<template>
	<view v-if="pageShow">
		<view class="mainpadding" style="padding-bottom: 150rpx;">
			<view class="flexbetween">
				<view class="hong_text main_size bold">
					<text style="font-size: 40rpx;color: #019891;margin-right: 10rpx;" class="bold"
						v-if="orderInfo.ordergood.order_type==3">時</text>
					<text v-if="orderInfo.ordergood.call_no">排號：{{orderInfo.ordergood.call_no}}</text>
				</view>
				<view class="hong_text main_size" v-show="orderInfo.status==0">未到店</view>
				<view class="lv_text main_size" v-show="orderInfo.status==1">已到店</view>
				<view class="huang_text main_size" v-show="orderInfo.status==2 && orderInfo.desk!=-1">
					{{orderInfo.desk}}號桌
				</view>
				<view class="hui_text main_size" v-show="orderInfo.status==88">用戶取消</view>
				<view class="lv_text main_size" v-show="orderInfo.status==99">已完成</view>
			</view>
			<view class="mainpadding_top ffffff radius">
				<view class="hei_text main_size bold">客戶名稱：{{orderInfo.username}}</view>
				<view class="hui_text margin_top main_size bold">客戶電話：{{orderInfo.phone}}</view>
				<view class="flexbetween margin_top" v-if="orderInfo.image">
					<view class="xiaohei main_size">支付憑證</view>
					<image class="listleftimg1 radius" :src="orderInfo.image_text" mode=""
						@click.stop="lbtpriview(0,[orderInfo.image_text])"></image>
				</view>
				<view class="hui_text margin_top main_size bold" v-if="orderInfo.ordergood.order_type!=3">
					客戶人數：兒童{{orderInfo.ernum}}人，老人{{orderInfo.oldnum}}人，共{{orderInfo.ernum+orderInfo.oldnum+orderInfo.crnum}}人
				</view>
				<view class="hui_text margin_top main_size bold" v-if="orderInfo.ordergood.order_type==3">
					客戶人數：<text v-for="(item,index) in cdbjhsf_data" :key="index">
						<text v-if="item.num!=0" class="margin_right1"><text
								class="huang_text">{{item.num}}</text>/{{item.name}}</text>
					</text>
				</view>
				<view class="huang_text margin_top main_size bold">預約時間：{{orderInfo.yuefenzu}} {{orderInfo.yuetime}}</view>
				<view class="lv_text margin_top main_size bold" v-show="orderInfo.status==99">
					完成時間：{{secondDate(orderInfo.updatetime,0,0)}}</view>
				<view class="hong_text margin_top main_size bold" v-show="orderInfo.status==88">
					取消時間：{{secondDate(orderInfo.updatetime,0,0)}}</view>
			</view>
			<view class="mainpadding_top ffffff radius" v-if="orderInfo.ordergood.ordergoodslist.length">
				<view class="xiaohei main_size">已選商品</view>
				<view class="padding_top3 line_top margin_top">
					<view class="flexbetween">
						<view class="text_a color_ling">訂單編號：{{orderInfo.ordergood.order_sn}}</view>
						<view class="text_x color_red">#{{orderInfo.ordergood.call_no}}</view>
					</view>
					<view class="flexleft margin_top" v-for="(ite,inde) in orderInfo.ordergood.ordergoodslist"
						:key="inde">
						<view class="goodsImg margin_right3">
							<image :src="ite.logoimage_text" mode=""></image>
						</view>
						<view class="flex1">
							<view class="text_a color_san bold">{{ite.goods_name}}</view>
							<view class="text_b color_six margin_top1 flexbetween" v-if="ite.wei || ite.hei">
								<text>尺寸：{{ite.wei}}*{{ite.hei}}</text>
								<text>用量：{{ite.formulacount}}{{ite.size}}</text>
							</view>
							<view class="xiaolan" v-if="ite.spunatdata_text && ite.spunatdata_text.length">規格：<text class="margin_right1"
									v-for="(value) in ite.spunatdata_text"
									:key="value.spunatid">{{value.spunatname}}*{{value.num}}&nbsp;&nbsp;&nbsp;</text>
							</view>
							<view class="flexbetween margin_top1">
								<view class="color_orange text_six">${{ite.d_price}}&nbsp;&nbsp;&nbsp;x{{ite.num}}
								</view>
								<view class="text_six color_orange">${{ite.price*ite.num}}</view>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="mainpadding_top ffffff radius" v-if="orderInfo.ordergood.tbmc || orderInfo.ordergood.tbcode">
				<view class="titletext hei_text bold">發票信息</view>
				<view class="flexbetween margin_top">
					<view class="hei_text main_size">類型</view>
					<view class="hui_text main_size" v-if="orderInfo.ordergood.opentype==0">紙本</view>
					<view class="hui_text main_size" v-if="orderInfo.ordergood.opentype==1">載具</view>
					<view class="hui_text main_size" v-if="orderInfo.ordergood.opentype==2">統編</view>
					<view class="hui_text main_size" v-if="orderInfo.ordergood.opentype==3">捐贈</view>
				</view>
				<view class="flexbetween margin_top" v-if="orderInfo.ordergood.opentype!=0">
					<view class="hei_text main_size" v-if="orderInfo.ordergood.opentype==1">手機載具</view>
					<view class="hei_text main_size" v-if="orderInfo.ordergood.opentype==2">統一編碼</view>
					<view class="hei_text main_size" v-if="orderInfo.ordergood.opentype==3">捐贈碼</view>
					<view class="hui_text main_size">{{orderInfo.ordergood.tbcode}}</view>

				</view>
				<view class="flexbetween margin_top">
					<view class="hei_text main_size" v-if="orderInfo.ordergood.tbmc">發票擡頭</view>
					<view class="hui_text main_size" v-if="orderInfo.ordergood.tbmc">{{orderInfo.ordergood.tbmc}}</view>
				</view>
			</view>
			<view class="mainpadding_top ffffff radius">
				<view class="flexbetween " v-if="orderInfo.ordergood.order_sn">
					<view class="hei_text main_size bold">訂單編號</view>
					<view class="hui_text main_size bold">{{orderInfo.ordergood.order_sn}}</view>
				</view>
				<view class="flexbetween margin_top" v-if="orderInfo.createtime">
					<view class="hei_text main_size bold">下單時間</view>
					<view class="hui_text main_size bold">{{secondDate(orderInfo.createtime,0,0)}}</view>
				</view>
				<view class="flexbetween margin_top" v-if="orderInfo.ordergood.order_type==3">
					<view class="hei_text main_size bold">人數基本價</view>
					<view class="huang_text main_size bold">${{orderInfo.ordergood.rs_price}}</view>
				</view>
				<view class="flexbetween margin_top" v-if="orderInfo.ordergood.order_type==3">
					<view class="hei_text main_size bold">商品總金額</view>
					<view class="huang_text main_size bold">
						${{Number(orderInfo.ordergood.countmoney)-Number(orderInfo.ordergood.rs_price)-Number(orderInfo.ordergood.fw_price)}}
					</view>
				</view>
				<view class="flexbetween margin_top" v-if="orderInfo.ordergood.order_type==3">
					<view class="hei_text main_size bold">服務費用</view>
					<view class="huang_text main_size bold">${{orderInfo.ordergood.fw_price}}</view>
				</view>
				<view class="flexbetween margin_top">
					<view class="hei_text main_size bold">總金額</view>
					<view class="huang_text main_size bold">${{orderInfo.ordergood.countmoney || 0}}</view>
				</view>
				<view class="flexbetween margin_top">
					<view class="hei_text main_size bold">已付金額</view>
					<view class="huang_text main_size bold">${{orderInfo.ordergood.paymoney || 0}}</view>
				</view>
				<view class="flexbetween margin_top">
					<view class="hei_text main_size bold">未付金額</view>
					<view class="hong_text main_size bold">${{orderInfo.ordergood.zhuimoney || 0}}</view>
				</view>
			</view>
		</view>
		<view class="posibottom mainpadding2 flexright ffffff">
			<view class="flexright flex_wrap">
				<view class="greyBtn margin_top1 margin_right3" v-show="orderInfo.status==0"
					@click="cancelOrder(orderInfo.id)">取消預約
				</view>
				<view class="orangeBtn margin_top1" v-show="orderInfo.status==0" @click="reach(orderInfo)">掃店家碼</view>
				<view class="greyBtn margin_top1" v-show="orderInfo.status==2" @click.stop="fuwuling(orderInfo)">服務鈴
				</view>
				<!-- 普通預約訂單點餐 -->
				<view class="orangeBtn margin_top1 margin_left3"
					@click.stop="goSelectGoods(orderInfo.shop_id,orderInfo.order_goods_id)"
					v-show="orderInfo.status==2 && orderInfo.order_goods_id && orderInfo.ordergood.order_type!=3">點餐
				</view>
				<!-- 計時點餐 -->
				<view class="orangeBtn margin_top1 margin_left3"
					@click.stop="gocdbSelectGoods(orderInfo.shop_id,orderInfo.id,orderInfo.ordergood.cdbtc_id)"
					v-show="orderInfo.status==2 && orderInfo.order_goods_id && orderInfo.ordergood.order_type==3">點餐
				</view>
				<view class="orangeBtn margin_top1 margin_left3" @click.stop="jiezhnag(orderInfo)"
					v-show="orderInfo.status==2 && Number(orderInfo.ordergood.zhuimoney)">結帳</view>
				<view class="orangeBtn margin_top1 margin_left3"
					v-show="orderInfo.status==2 && Number(orderInfo.ordergood.zhuimoney)"
					@click.stop="pzshow=true;currentid=orderInfo.id;uppzflag=3">上傳憑證</view>
				<view class="greyBtn margin_top1" v-show="orderInfo.status==99||orderInfo.status==88"
					@click.stop="removeOrder(orderInfo.id)">刪除記錄</view>
			</view>
		</view>
		<u-modal :show="showConfirm" showCancelButton confirmColor="#ffb800" @cancel="showConfirm=false"
			confirmText="確認" cancelText="取消" @confirm="orderConfirm">
			<view class="slot-content color_ling text_weight text">
				{{text}}
			</view>
		</u-modal>
		<!-- 上傳支付憑證 -->
		<u-modal :show="pzshow" title="上傳憑證" confirmColor="#ffb800" confirmText="確認" @confirm="upconfirm"
			cancelText="取消" @cancel="pzshow=false" showCancelButton>
			<view class="slot-content" style="width: 730rpx;">
				<view class="flexcenter">
					<view class="itemimgBox flexcenter margin_top2" v-for="(item,index) in images_text" :key="index">
						<!-- 已上傳 -->
						<view class="listleftimg1 radius">
							<image class="radius" :src="item" mode=""></image>
							<view class="deleteimg" @click="delindex(index,images,images_text)"></view>
						</view>
					</view>
					<view class="itemimgBox flexcenter margin_top2" @click="uploadImg(1,images,images_text)"
						v-if="images.length<1"><!-- 未上傳 -->
						<image class="listleftimg1 radius" src="@/static/images/mine/noImage.png" mode=""></image>
					</view>
				</view>
			</view>
		</u-modal>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				pageShow: false,
				listid: "",
				orderInfo: {},
				showConfirm: false,
				text: "你確定要放棄此訂單嗎？",
				id: "", //操作的订單id
				orderType: 0, //0取消 1跳过
				ishave_zt: true, //是否有使用，
				images: [],
				images_text: [],
				currentid: "",
				pzshow: false,
				uppzflag: 1, //1商品訂單上傳憑證，2呼叫訂單定金上傳，4呼叫訂單尾款上傳，3預約訂單上傳
				cdbjhsf_data: []
			}
		},
		onLoad(options) {
			this.listid = options.id
			this.getztList()
		},
		onShow() {
			this.getDetail()
		},
		methods: {
			fuwuling(item) {
				let that = this
				uni.showLoading({
					mask: true,
					title: "請稍後"
				})
				httpRequest.request('/api/ordermake/callService', 'GET', {
					shop_id: item.shop_id,
					desk: item.desk,
					user_id: uni.getStorageSync('user_id')
				}).then(res => {
					uni.hideLoading()
					if (res.code == 1) {
						httpRequest.toast(res.msg)
					}
				})
			},
			async getDetail() { //確認放弃订單
				let res = await this.http.request('/api/Ordermake/deailOrdermake', 'POST', {
					id: this.listid
				})
				this.orderInfo = res.data
				if (this.orderInfo.ordergood.order_type == 3) {
					this.cdbjhsf_data = JSON.parse(res.data.cdbjhsf_data)
				}
				this.pageShow = true
			},
			// 預約訂單開始
			async reach(item) { //到達
				uni.navigateTo({
					url: "/pages_order/yuyuedaoda?id=" + item.id + "&shop_id=" + item.shop_id
				})
			},
			jiezhnag(item) { //預約訂單結帳
				uni.navigateTo({
					url: "/pages_index/payment?msg=" + encodeURIComponent(JSON.stringify({
						id: item.order_goods_id,
						paymoney: item.ordergood.zhuimoney,
						order_type: 4,
						shop_id: item.shop_id,
						call_no: item.call_no
					}))
				})
			},
			goSelectGoods(id, order_id) { //點餐選擇商品
				uni.setStorageSync("reservation_order_id", order_id)
				uni.navigateTo({
					url: `/pages_order/selectGoodsList?id=${id}`
				})
				// uni.navigateTo({
				// 	url: `/pages_order/selectGoods?id=${id}`
				// })
			},
			cancelOrder(id) { //商品、預約取消訂單
				this.id = id
				this.text = "您確定要取消此訂單吗？"
				this.orderType = 0
				this.showConfirm = true
			},
			removeOrder(id) { //商品、預約刪除訂單
				this.id = id
				this.text = "您確定要刪除此訂單吗？"
				this.orderType = 1
				this.showConfirm = true
			},
			async orderConfirm() { //確認 取消訂單/刪除訂單
				let url = "",
					text = "";
				if (this.orderType == 0) {
					url = '/api/Ordermake/endOrdermake'
					text = "取消成功"
				} else if (this.orderType == 1) {
					url = "/api/ordermake/delOrdergoods"
					text = "刪除成功"
				}
				let _this = this
				let res = await this.http.request(url, 'POST', {
					id: this.id
				})
				if (res.code == 1) {
					this.http.toast(text)
					this.showConfirm = false
					if (text == "刪除成功") {
						setTimeout(() => {
							uni.navigateBack(1)
						}, 1000)
						return false
					}
					this.getDetail()
				} else if (res.code == 0) {
					this.http.toast(res.msg)
				} else {
					this.http.toast('系統處理中，請稍後再試');
				}
			},
			gocdbSelectGoods(id, order_id, cdbtc_id) {
				uni.setStorageSync("order_make_id", order_id)
				uni.navigateTo({
					url: "/pages_mine/zizhucan?cdbtc_id=" + cdbtc_id + "&shop_id=" + id
				})
			},
			uploadImg(value, upImgs, upImgs_text) { //上傳圖片
				let _this = this;
				let num = Number(value) - upImgs.length;
				if (num <= 0) {
					return false;
				}
				uni.showActionSheet({
					itemList: ['照機', '相簿'],
					success: function(res) {
						// 選擇照機走0
						if (res.tapIndex == 0) {
							httpRequest.chooseImage(num, ['camera']).then(res => {
								for (var i = 0; i < res.length; i++) {
									_this.uploadImageService(res[i], upImgs, upImgs_text)
								}
							}).catch(err => {});
						}
						// 選擇相簿走1
						if (res.tapIndex == 1) {
							httpRequest.chooseImage(num, ['album']).then(res => {
								for (var i = 0; i < res.length; i++) {
									_this.uploadImageService(res[i], upImgs, upImgs_text)
								}
							}).catch(err => {});
						}
					},
					fail: function(res) {}
				});
			},
			delindex(index, upImg, upImgs_text) {
				upImg.splice(index, 1)
				upImgs_text.splice(index, 1)
			},
			uploadImageService(url, upImg, upImgs_text) {
				let _this = this;
				this.http.uploadFile('/api/common/upload', url).then(res => {
					let image_item = res.fullurl;
					upImg.push(res.url)
					upImgs_text.push(image_item);
				}).catch(err => {});
			},
			upconfirm() {
				if (this.images.length == 0) {
					httpRequest.toast("請上傳圖片")
				}
				this.pzshow = false
				let url = "/api/Ordermake/updateOrderImage"
				let data = {
					id: this.currentid,
					image: this.images.join()
				}
				httpRequest.request(url, 'GET', data).then(res => {
					httpRequest.toast(res.msg);
					if (res.code == 1) {
						this.images = []
						this.images_text = []
						this.getDetail()
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	::v-deep.u-transition {
		z-index: 10 !important;
	}

	.beihuolable {
		background-color: #fff3e6;
		padding: 5rpx 10rpx;
		border: 1rpx solid #FF8505;
	}

	.posibottom {
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		box-sizing: border-box;
	}
</style>
<style lang="scss" scoped>
	.margin_right3 {
		margin-right: 30rpx;
	}

	.goodsImg {
		width: 157rpx;
		height: 157rpx;
		position: relative;

		image {
			width: 100%;
			height: 100%;
			border-radius: 14rpx;
		}

		.shipment {
			// width: 71rpx;
			// height: 30rpx;
			// line-height: 30rpx;
			padding: 4rpx;
			box-sizing: border-box;
			text-align: center;
			background: #13C463;
			border-radius: 14rpx 0rpx 14rpx 0rpx;
			font-size: 18rpx;
			font-family: PingFang SC-Medium, PingFang SC;
			font-weight: 500;
			color: #FFFFFF;
			position: absolute;
			left: 0;
			top: 0;
		}
	}

	.listleftimg1 {
		width: 150rpx;
		min-width: 150rpx;
		height: 150rpx;
		position: relative;

		image {
			width: 100%;
			height: 100%;
		}
	}

	.bghuang {
		background-color: #feb800;
		padding: 15rpx 30rpx;
	}

	::v-deep.u-tabs__wrapper__nav__item {
		flex: 1;
		white-space: nowrap;
	}
</style>